package travianBot.botScripts;

import java.util.HashMap;

import travianBot.TravianBot;
import travianBot.TravianBotException;

public abstract class TravianScript {

	public static final String TYPE_RESOURCE = "r";
	public static final String TYPE_BUILDING = "b";
	public static final String SEND_RESOURCE = "send";
	public static final String TROOP_ARMOR_UPGRADE = "armor";
	
	int 		cursorPosition = 0;
	int 		loopCounter;
	String 		villageName;
	String		type;	
	boolean		scriptExhausted=false;	
	
	public TravianScript(){};
	
	public TravianScript(String csvString){};
	
	public abstract void init(String cvsString);
	
	//public void runScript(TravianBot travianBot) throws TravianBotException;
	
	public abstract void runScript(TravianBot travianBot, HashMap<String,String> sessionInfoMap) throws TravianBotException;
	
	public static TravianScript getResourceScriptFactory(String csvLine){
		TravianScript returnScript = null;
		String[] tokens = csvLine.split(",");
		
		int cursorToken 		= Integer.parseInt(tokens[0]);
		String villageNameToken = tokens[1];
		String typeToken 		= tokens[2];
		
		if(typeToken.equals(TravianScript.TYPE_RESOURCE)){
			returnScript = new ResourceScript(csvLine);
		}else if(typeToken.equals(TravianScript.TYPE_BUILDING)){
			returnScript = new BuildingScript(csvLine);
		}else if(typeToken.equals(TravianScript.SEND_RESOURCE)){
			returnScript = new DonateResourceScript(csvLine);
		}else if(typeToken.equals(TravianScript.TROOP_ARMOR_UPGRADE)){
			returnScript = new ArmoryScript(csvLine);
		}
		return returnScript;
	}
	
	/**
	 * tidyup method to clean up the session.
	 * Normally used to reset the session before starting a complete script run
	 * @param sessionInfoMap
	 */
	public void initialiseSession(HashMap<String,String> sessionInfoMap){}
	
	public int getCursorPosition() {
		return cursorPosition;
	}

	public void setCursorPosition(int cursorPosition) {
		this.cursorPosition = cursorPosition;
	}

	public int getLoopCounter() {
		return loopCounter;
	}

	public void setLoopCounter(int loopCounter) {
		this.loopCounter = loopCounter;
	}

	public String getVillageName() {
		return villageName;
	}

	public void setVillageName(String villageName) {
		this.villageName = villageName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	};
	
	

}